dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleLob Class / Write Method / Write(Byte[],Int32,Int32) Method
An array of bytes.
The zero-based byte offset in the buffer.
The amount of bytes to be written to the current stream.
Example

In This Topic
    Write(Byte[],Int32,Int32) Method
    In This Topic
    Writes a sequence of bytes to the current OracleLob stream, and advances the current position within this stream by the number of bytes written.
    Syntax
    'Declaration
     
    Public Overloads Overrides Sub Write( _
       ByVal buffer() As Byte, _
       ByVal offset As Integer, _
       ByVal count As Integer _
    ) 
    public override void Write( 
       byte[] buffer,
       int offset,
       int count
    )

    Parameters

    buffer
    An array of bytes.
    offset
    The zero-based byte offset in the buffer.
    count
    The amount of bytes to be written to the current stream.
    Remarks
    If the write operation is successful, the position within the stream advances by the number of bytes written.

    Note that writing data to OracleLob object results in immediate data transfer to server.

    Example
    In this example data is written to OracleLob object from a stream.
    public void UploadBlob(OracleConnection myConnection)
    {
      FileStream fs = new FileStream("D:\\Tmp\\_Water.bmp", FileMode.Open, FileAccess.Read);
      BinaryReader r = new BinaryReader(fs);
      myConnection.Open();
      OracleLob myLob = new OracleLob(myConnection,OracleDbType.Blob);
      int streamLength = (int)fs.Length;
      myLob.Write(r.ReadBytes(streamLength), 0, streamLength);
      OracleCommand myCommand = new OracleCommand("INSERT INTO Pictures (ID, PicName, Picture) VALUES(1,'Water',:Pictures)", myConnection);
      OracleParameter myParam = myCommand.Parameters.Add("Pictures", OracleDbType.Blob);
      myParam.OracleValue = myLob;
      try
      {
        Console.WriteLine(myCommand.ExecuteNonQuery() + " rows affected.");
      }
      finally
      {
        myConnection.Close();
        r.Close();
        fs.Close();
      }
    }
    Public Sub UploadBlob(ByVal myConnection As OracleConnection)
      Dim fs As FileStream = New FileStream("D:\Tmp\_Water.bmp", FileMode.Open, FileAccess.Read)
      Dim r As BinaryReader = New BinaryReader(fs)
      myConnection.Open()
      Dim myLob As OracleLob = New OracleLob(myConnection, OracleDbType.Blob)
      Dim streamLength As Int32 = fs.Length
      myLob.Write(r.ReadBytes(streamLength), 0, streamLength)
      Dim myCommand As OracleCommand = New OracleCommand("INSERT INTO Pictures (ID, PicName, Picture) VALUES(1,'Water',:Pictures)", myConnection)
      Dim myParam As OracleParameter = myCommand.Parameters.Add("Pictures", OracleDbType.Blob)
      myParam.OracleValue = myLob
      Try
        Console.WriteLine(myCommand.ExecuteNonQuery() & " rows affected.")
      Finally
        myConnection.Close()
        r.Close()
        fs.Close()
      End Try
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also